package com.tff.gmall.manger.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.tff.gmall.beans.PmsSkuInfo;
import com.tff.gmall.service.PmsSkuInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@CrossOrigin
public class SkuController {

    @Reference
    private PmsSkuInfoService pmsSkuInfoService;

    @RequestMapping(value = "/saveSkuInfo")
    @ResponseBody
    public String saveSkuInfo(@RequestBody PmsSkuInfo pmsSkuInfo) {

        pmsSkuInfo.setProductId(pmsSkuInfo.getSpuId());
        System.out.println(pmsSkuInfo.toString());
        //默认图片的处理
        if (StringUtils.isBlank(pmsSkuInfo.getSkuDefaultImg())) {
            pmsSkuInfo.setSkuDefaultImg(pmsSkuInfo.getSkuImageList().get(0).getImgUrl());
        }
        Integer integer = pmsSkuInfoService.saveSkuInfo(pmsSkuInfo);
        return "success";
    }
}
